//
//  UIBarButtonItem+Extension.m
//  XXProject
//
//  Created by xiexi on 2017/3/3.
//  Copyright © 2017年 xiexi. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"
#define ThemeColor [UIColor orangeColor]
#define normolColor [UIColor lightGrayColor]
@implementation UIBarButtonItem (Extension)

+ (UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action image:(NSString *)image highImage:(NSString *)highImage
{
   
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 设置图片
    [btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    //    UITrackingRunLoopMode
    
    // 设置尺寸
    //btn.size = btn.currentBackgroundImage.size;
    btn.bounds = CGRectMake(0, 0, btn.currentBackgroundImage.size.width, btn.currentBackgroundImage.size.height);
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

+(UIBarButtonItem *)itemWithThemeBtnTitle:(NSString *)title target:(id)obj action:(SEL)selector
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:obj action:selector forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font=[UIFont systemFontOfSize:15];
    [btn setTitleColor:ThemeColor forState:UIControlStateNormal];
    //    [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn sizeToFit];
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}
+(UIBarButtonItem *)itemWithThemeBtnTitle:(NSString *)title image:(NSString *)imageName target:(id)obj action:(SEL)selector
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:obj action:selector forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font=[UIFont systemFontOfSize:15];
    [btn setTitleColor:ThemeColor forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btn sizeToFit];
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

+(UIBarButtonItem *)itemWithNormolBtnTitle:(NSString *)title image:(NSString *)imageName target:(id)obj action:(SEL)selector
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:obj action:selector forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font=[UIFont systemFontOfSize:15];
    [btn setTitleColor:normolColor forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btn sizeToFit];
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

+(UIBarButtonItem *)itemWithThemeBackArrowWithTarget:(id)obj action:(SEL)selector{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:obj action:selector forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundImage:[self themeBackArrow] forState:UIControlStateNormal];
    //    btn.bounds = CGRectMake(0, 0, 30, 30);
    //    [btn setImageEdgeInsets:UIEdgeInsetsMake(3, 0, 0, 22)];
    //让btn保持图片大小
    btn.bounds = CGRectMake(0, 0, btn.currentBackgroundImage.size.width, btn.currentBackgroundImage.size.height);
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    
    
}
+(UIBarButtonItem *)itemWithWhiteBackArrowWithTarget:(id)obj action:(SEL)selector{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:obj action:selector forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundImage:[self whiteBackArrow] forState:UIControlStateNormal];
    btn.bounds = CGRectMake(0, 0, btn.currentBackgroundImage.size.width, btn.currentBackgroundImage.size.height);
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    
    
}


+(UIBarButtonItem *)itemWithThemeBackArrow{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:[self themeBackArrow] forState:UIControlStateNormal];
    btn.bounds = CGRectMake(0, 0, btn.currentBackgroundImage.size.width, btn.currentBackgroundImage.size.height);
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

+(UIBarButtonItem *)itemWithWhiteBackArrow
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:[self whiteBackArrow] forState:UIControlStateNormal];
    btn.bounds = CGRectMake(0, 0, btn.currentBackgroundImage.size.width, btn.currentBackgroundImage.size.height);
    return [[UIBarButtonItem alloc] initWithCustomView:btn];}

+(UIImage *)themeBackArrow{
    return [UIImage imageNamed:@"navigationbar_back_withtext_highlighted"];
}
+(UIImage *)whiteBackArrow{
    return [UIImage imageNamed:@"navigationbar_back_withtext"];
}
@end


